package cn.com.web.Servlet;

import cn.com.service.CustomerService;
import cn.com.service.RoomService;
import cn.com.service.impl.CustomerServiceImpl;
import cn.com.service.impl.RoomServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/DeleteRoomServlet")
public class DeleteRoomServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取所有id
        String[] ruids = request.getParameterValues("ruid");
        //2.调用service删除
        RoomService service=new RoomServiceImpl();
        if (ruids.length<1 || ruids==null){
            String ruidd=request.getParameter("ruid");
            if (ruidd == null)
            {
                request.getRequestDispatcher("FindRoomByPageServlet?currentPage=1&rows=5")
                        .forward(request,response);
                return;
            }
            service.delteRoombyid(ruidd);
        }else for (String ruid : ruids) {
            service.delteRoombyid(ruid);
        }
        //请求转发到ShowCustomerServlet
        request.getRequestDispatcher("FindRoomByPageServlet?currentPage=1&rows=5").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
